//
//  XMGWebVc.m
//  YLDragZoomCycleViewDemo
//
//  Created by xhkj on 2018/7/20.
//  Copyright © 2018年 张雨露. All rights reserved.
//

#import "XMGWebVc.h"

@interface XMGWebVc ()<UIWebViewDelegate>
@property (strong, nonatomic) UIWebView *webView;

- (IBAction)backButton:(id)sender;
@end

@implementation XMGWebVc

- (void)viewDidLoad {
    [super viewDidLoad];
     _titleLable.text=_title_Lable;
     
    
    self.view.backgroundColor=[UIColor whiteColor];
    self.webView =[[UIWebView alloc]initWithFrame:CGRectMake(0, 64, XMGScreenW, XMGScreenH-64)];
    _webView.backgroundColor = [UIColor cyanColor];
    for (UIView * views in [self.webView subviews]) {
        if ([views isKindOfClass:[UIScrollView class]]) {
            //去掉水平方向的滑动条
            [(UIScrollView *)views setShowsHorizontalScrollIndicator:NO];
            //去掉垂直方向的滑动条
            [(UIScrollView *)views setShowsVerticalScrollIndicator:NO];
            for (UIView * inScrollView in views.subviews) {
                if ([inScrollView isKindOfClass:[UIImageView class]]) {
                    //隐藏上下滚动出边界时的黑色的图片
                    inScrollView.hidden = YES;
                }
            }
        }
    }
     
      
    _webView.delegate = self;
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
    [self.view addSubview:self.webView];
    self.webView.scrollView.contentInset=UIEdgeInsetsMake(0, 0, 0, 0);
}

//用苹果自带的返回键按钮处理如下(自定义的返回按钮) 
- (IBAction)backButton:(id)sender {
    if ([self.webView canGoBack]) {
        [self.webView goBack];
        
    }else{
        [self.view resignFirstResponder];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

//如果是H5页面里面自带的返回按钮处理如下:
#pragma mark - webViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString * requestString = [[request URL] absoluteString];
    requestString = [requestString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //获取H5页面里面按钮的操作方法,根据这个进行判断返回是内部的还是push的上一级页面
    if ([requestString hasPrefix:@"goback:"]) {
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self.webView goBack];
    }
    return YES;
}

@end
